package com.neu.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.neu.mapper.GoodsmanageMapper;
import com.neu.po.Goodsmanage;
import com.neu.po.GoodsmanageExample;


@Service
public class GoodsmanageServiceImpl implements GoodsmanageService {
	
	@Autowired
	private GoodsmanageMapper goodsmanageMapper;
	
	
	@Override
	public PageInfo<Goodsmanage> getPaged(int pageNum, int pageSize, String keyword) {
		// TODO Auto-generated method stub
		GoodsmanageExample example = new GoodsmanageExample();
		  com.neu.po.GoodsmanageExample.Criteria criteria = example.createCriteria();
		 com.neu.po.GoodsmanageExample.Criteria criteria2 = example.createCriteria();
		
		 criteria.andDelmarkEqualTo(1).andGoodcodeLike("%"+keyword+"%");
		 criteria2.andDelmarkEqualTo(1).andGoodnameLike("%"+keyword+"%");
		
		example.or(criteria2);
		
		PageHelper.startPage(pageNum, pageSize);
		
		List<Goodsmanage> list = goodsmanageMapper.selectByExample(example);
		
		PageInfo<Goodsmanage> pageInfo = new PageInfo<>(list);
		
		return pageInfo;
		
		
	}
	@Override
	public List<Goodsmanage> getAll() {
		// TODO Auto-generated method stub
		GoodsmanageExample example = new GoodsmanageExample();
		return goodsmanageMapper.selectByExample(example);
	}
	@Override
	public int insert(Goodsmanage goodsmange) {
		// TODO Auto-generated method stub
		
		return goodsmanageMapper.insert(goodsmange);
	}
	@Override
	public int delete(int id) {
		// TODO Auto-generated method stub
		return goodsmanageMapper.deleteByPrimaryKey(id);
	}
	@Override
	public int update(Goodsmanage goodsmange) {
		// TODO Auto-generated method stub
		return goodsmanageMapper.updateByPrimaryKey(goodsmange);
	}
	@Override
	public int batchDelete(List<Integer> ids) {
		// TODO Auto-generated method stub
		GoodsmanageExample example = new GoodsmanageExample();
		example.or().andIdIn(ids);
		return goodsmanageMapper.deleteByExample(example);
	}
	

}
